<html>
<head>
	<script type="text/javascript">
		var aJaxURL			= "server-side/letters/letterA.action.php";						//server side folder url
		var serv_aJaxURL	= "server-side/letters/letterA/service_list.action.php";		//server side folder url
		var guar_aJaxURL	= "server-side/letters/letterA/guarante_list.action.php";		//server side folder url
		var seoyURL			= "server-side/seoy/seoy.action.php";							//server side folder url
        var wsdlURL			= "server-side/wsdl/wsdl.action.php";							//server side folder url
		var tName			= "example";													//table name
		var fName			= "add-edit-form";												//form name
		var ids 			= "";
		var tbName			= "tabs";	
		var client_ob_trans = "0";
		var trans_price     =  0;
		var trans_type      =  0; 
		var filter          =  'AND a_letter.b_letter_status=0'  ;
		$(document).ready(function () {
			gsUnity.GetTabs("tabs");
			LoadTable(tName);
			/* Add Button ID, Delete Button ID */
			GetButtons("add_button", "delete_button");
			$("#print_empty").button({
	            icons: {
	                primary: "ui-icon-print"
	            }
        	});

			$("#save_button").button({
	            icons: {
	                primary: "ui-icon-disk"
	            }
        	});
			SetEvents("add_button", "delete_button", "check-all", tName, fName, aJaxURL);

			Check(30000,aJaxURL);

		    $("#add-edit-form").on( "dialogclose", function() {
		    	$("#chechedStatus").val("true");
		    });
		});

        //SeoYyy
		$(document.body).click(function (e) {
        	$("#client_object").autocomplete("close");
        	$("#client_proruction").autocomplete("close");
        });

		function LoadTable(table){
			var menuLength	= [[10], [10]];
			var local_id	= $("#latter_id").val();
			var warehouse_id	= $("#warehouse_id").val();			
		    filter             =  ' AND a_letter.`status`=1  AND warehouse.`status` <2';
			var tab = GetSelectedTab("tabs");
			if(tab==1) filter  = 'AND a_letter.`status` in (1,2) AND warehouse.`status` >1'  ;			
			if(tab==2) filter  = 'AND a_letter.`status` =3'  ;
			if(tab==3) filter  = 'AND a_letter.`status` =4'  ;
			if(tab==4) filter  = 'AND a_letter.`status` =5'  ;
			if(tab==5) filter  = 'AND a_letter.`status` =6'  ;
			
			switch (table) {
			
				case "recomendation":
					/* Table ID, aJaxURL, Action, Colum Number, Custom Request, Hidden Colum, Menu Array */
					GetDataTable(table, aJaxURL, "recomendation", 5, "&date=" + $("#day_date").val() + "&est_time=" + $("#est_time").html() , 0, menuLength, 1, "asc");
					$(".dataTable_content").css("min-height", "200px");
					break;
				case	'paln_end_date_list':
					GetDataTable(table, aJaxURL, "get_planed_end_date", 6, "", 0, menuLength, 0, "");
					$(".dataTable_content").css("min-height", "200px");
					break;
				case	'same_letter_list':
					GetDataTable(table, aJaxURL, "get_same_letters", 6, "cobj=" + $("#client_object").val(), 0, menuLength, 1, "asc");

					break;
				case "service_list":
					/* Table ID, aJaxURL, Action, Colum Number, Custom Request, Hidden Colum, Menu Array */
					GetDataTable(table, serv_aJaxURL, "get_list", 3, "local_id=" + local_id + "&warehouse_id="+warehouse_id, 0, menuLength, 1, "asc");
					//LoadTable('guarante_list');
					break;
				case "guarante_list":
					/* Table ID, aJaxURL, Action, Colum Number, Custom Request, Hidden Colum, Menu Array */
					GetDataTable(table, guar_aJaxURL, "get_list", 3, "local_id=" + local_id + "&warehouse_id="+warehouse_id, 0, menuLength, 1, "asc");
					break;
				default:
					/* Table ID, aJaxURL, Action, Colum Number, Custom Request, Hidden Colum, Menu Array */
	                GetDataTable(tName, aJaxURL, "get_list", 7, "filter="+filter, 0, "", 0, "desc");
			}
		}

		function LoadDialog(form){
			switch (form) {
			 case "empty-form":
					$.ajax({
				        url: aJaxURL,
					    data: "act=empty-form&cn=" + client_name,
				        success: function(data) {
							if(typeof(data.error) != "undefined"){
								if(data.error != ""){
									alert(data.error);
								}else{
									$("#empty-form").html(data.page);
								}
							}
					    }
				    });
				    var button = {
				            "save": {
				                text: "ბეჭდვა",
				                id: "save-empty",
				                click: function () {
					                if ($("#receiver_").val()!=0 & $("#quantity_").val()>0) {
				        	    	var link = $(this).attr("str");
				        	    	link = "server-side/print/print_EmptyLetterA.php?receiver="+$("#receiver_ :selected").text()+"&car="+$("#car_id_ :selected").text()+"&quantity="+$("#quantity_").val()+"&car_id="+$("#car_id_").val()+"&receiver_id="+$("#receiver_").val();
				        	    	var newWin = window.open(link, "JSSite", "width=800,height=800,resizable=yes,scrollbars=yes,status=yes");
				        	    	newWin.focus();
				        	    	newWin.onload = function() {
				        	    		newWin.print();
				        		    }

				                }else{ alert("შემოიტანეთ ყველა მონაცემი სწორად");}
					                }
				            },
				            "cancel": {
				                text: "დახურვა",
				                id: "cancel-dialog",
				                click: function () {
				                    $(this).dialog("close");
				                }
				            }
				        };
				 GetDialog("empty-form", "auto", "auto",button);
			   break;
			 case "show-planed-end-date":
				var buttons = {
			        "cancel": {
			            text: "დახურვა",
			            id: "cancel-dialog",
			            click: function () {
			            	$(this).dialog("close");
			            }
			        }
			    };
				GetDialog("show-form", 850, "auto", buttons);
				LoadTable("paln_end_date_list");
				GetDate("day_date");
				LoadTable("recomendation");
			    $(document).on("change", "#day_date", function () {
			    	var day			= $("#day_date").val();
			    	var est_time	= $("#est_time").val();
			    	LoadTable("recomendation", day, est_time);
			    });

				break;
			case "show-same-letters":
				var buttons = {
			        "cancel": {
			            text: "დახურვა",
			            id: "cancel-dialog",
			            click: function () {
			            	$(this).dialog("close");
			            }
			        }
			    };
				GetDialog("show-form", 870, "auto", buttons);
				LoadTable("same_letter_list");

				break;
			case "add-edit-service-form":
	                $("#client_object").attr("disabled", "disabled");
					$("#client_object_btn").button("disable");

					var client_name = $("#client_object").val();
					var client_id	= GetClientID(client_name);
					SeoY("client_proruction", seoyURL, "client_cartridge", "id=" + client_id, 0);
					var buttons = {
				        "save": {
				            text: "დამატება",
				            id: "add-service",
				            click: function () {
				            }
				        }
				    };
					GetDialog(form, 500, "auto", buttons);
					if( !empty( $("#service_id").val() ) ){
						$("#client_proruction").attr("disabled", "disabled");
						$("#client_proruction_btn").attr("disabled", "disabled");
					}

					break;
			case "add-edit-guarante-form":
	                $("#client_object").attr("disabled", "disabled");
					$("#client_object_btn").button("disable");

					var client_name = $("#client_object").val();
					var client_id	= GetClientID(client_name);

					//var a_letter_id	= $("#latter_id").val();
					SeoY("client_guarante_proruction", seoyURL, "client_cartridge", "id=" + client_id, 0);
					 $(document).on("blur", "#client_guarante_proruction", function () {
						 	var cart_name 	= $("#client_guarante_proruction").val();
				        	SeoY("serial_number", seoyURL, "client_serial_number", "id=" + client_id+"&cart_name="+cart_name, 0);
						});

					var buttons = {
				        "save": {
				            text: "დამატება",
				            id: "add-guarante",
				            click: function () {
				            }
				        },
			        "cancel": {
			            text: "დახურვა",
			            id: "cancel-dialog",
			            click: function () {
			            	$(this).dialog("close");
			            }
			        }
				    };
					GetDialog(form, 500, "auto", buttons);
					$('#serial_number').focus();
				    if ($("#guarante_id").val()>0){
				    	$("#add-guarante").button("disable");
					    }

					break;
//////////--------------------------------------------------------------------add/edit--------------------------------------------------------------------------
			default:
					ClearDB();
					GetDateTimes("request_date");
					GetDateTimes("end_date");
					GetDateTimes("planed_end_date");
					SeoY("client_object", seoyURL, "client_objects", "", 0);
					var buttons = {
					        "work–blank": {
					            text: "A ბეჭდვა",
					            id: "work–blank",
					            click: function () {
					            }
					        },
					         "b-print": {
					            text: "B ბეჭდვა",
					            id: "b-print",
					            click: function () {
					            }
					        },
					        "continue-rs": {
					            text: "rs.ge - ზე დასრულება",
					            id: "continue-rs",
					            click: function () {
					            }
					        },
					        "ref-rs": {
					            text: "rs.ge - ზე  გაუქმება",
					            id: "ref-rs",
					            click: function () {
					            }
					        },
					        "add-rs": {
					            text: "rs.ge - ზე გააქტიურება",
					            id: "add-rs",
					            click: function () {
					            }
					        },
					        "save": {
					            text: "შენახვა",
					            id: "save-dialog",
					            click: function () {
					            }
					        },
					        "cancel": {
					            text: "დახურვა",
					            id: "cancel-dialog",
					            click: function () {
					                $(this).dialog("close");
					            }
					        }
					};
					/* Dialog Form Selector Name, Buttons Array */
					GetDialog(form, 950, "auto", buttons);
					GetButtons("add_button_serv", "delete_button_serv");
					GetButtons("add_button_guar", "delete_button_guar");

					var id			= $("#latter_id").val();
					var overhead_id	= $("#overhead_id").val();
					var req_id      = $("#req_id").val();
					clien_obj       = $("#client_objects_id").val();
					var local_id		= ids[0];
					var warehouse_id	= ids[1];
					//alert("sd");

					if(empty(req_id))
					{ 	$("#add-rs").button("disable");

					}else{
					    $("#client_object_btn").button("disable");
					    $("#client_object").prop('disabled', true);
						}

					if($("#finish_date").val()!=""){
						$("#continue-rs").button("disable");
						$("#add-rs").button("disable");
						$("#ref-rs").button("disable");
						}
					if(empty(overhead_id) || overhead_id=='0'){
						$("#continue-rs").button("disable");
						$("#ref-rs").button("disable");
						$("#add-rs").button("enable");
					}else{
						$("#add-rs").button("disable");
						}

					LoadTable("service_list");
					LoadTable("guarante_list");

					if(empty(id)){
						$(".inner-table").find(":input").prop("disabled", true);
						$("#planed_end_date").attr("disabled", "disabled");
						$("#end_date").attr("disabled", "disabled");
						$("#request_date").attr("disabled", "disabled");
						$("#source").attr("disabled", "disabled");
						$("#responsible_person").attr("disabled", "disabled");
						$("#car_id").attr("disabled", "disabled");
						$("#show_planed_end_date").attr("disabled", "disabled");
						$("#show_same_letters").attr("disabled", "disabled");


						$("#latter_id").val(local_id);
						$("#warehouse_id").val(warehouse_id);
					}else{
						buttons = {
							"cancel": {
					            text: "დახურვა",
					            id: "cancel-dialog",
					            click: function () {
					                $(this).dialog("close");
					            }
					        }
	                    };

						//$("#" + form).dialog("option", "buttons", buttons);
					}
					SetEvents("add_button_serv", "delete_button_serv", "check-all-serv", "service_list", "add-edit-service-form", serv_aJaxURL);
					SetEvents("add_button_guar", "delete_button_guar", "check-all-guar", "guarante_list", "add-edit-guarante-form", guar_aJaxURL);
					$("#chechedStatus").val("false");
			}
		}

		$(document).on("click","#add_button", function () {
			ids = GetLocalID();
		});
	    // Add - Save
	    $(document).on("click", "#save-dialog", function () {
	    	var letter_id = $("#latter_id").val();
	    	CheckPlannedEndDate(letter_id);
	    	SaveLatter(letter_id, false);
		});

	    // Add - RS
	    $(document).on("click", "#add-rs", function () {
	    	$("#client_ob_trans_div").remove();
	    	client_ob_trans=$("#client_ob_trans").val();
		    if(client_ob_trans>0){
		    	$.getJSON( "server-side/letters/empty_latter.action.php?act=trans_type", function( data ) {
		    		 $("body").append("<div id='client_ob_trans_div' title='ტრანსპორტირების ღირებულება'> შემოიტანეთ  ტრანსპორტირების  ღირებულება<input id='client_ob_trans_price' class='inpt' value='7.00' step='0.01' type='number'><br>აირჩიეთ ტრანსპორტირების ტიპი<br><select class='inpt' id='client_ob_trans_type'>"+data.data+"</select></div>");
	    	    
		    var button = {
		            "save": {
		                text: "გაგზავნა",
		                id: "",
		                click: function () {
		        		    var letter_id	= $("#latter_id").val();
		        		    trans_price=$("#client_ob_trans_price").val();
		        		    trans_type =$("#client_ob_trans_type").val()
		        		    
		        		    SaveLatter(letter_id, true);
		        		    $("#client_ob_trans_div").remove();
		        		    //trans_price=0;
		        		    //trans_type =0;
	
		                }
		            },
		            "cancel": {
		                text: "დახურვა",
		                id: "cancel-dialog",
		                click: function () {
		                	$("#client_ob_trans_div").remove();
		                    $(this).dialog("close");
		                }
		            }
		        };

		    GetDialog('client_ob_trans_div', 300, 250, button);
		    	})}
		    else{
		    var letter_id	= $("#latter_id").val();
		    SaveLatter(letter_id, true);
		    }
		});

	    // Confit - RS
	    $(document).on("click", "#continue-rs", function () {
		    var letter_id	= $("#latter_id").val();
            $.ajax({
                url: aJaxURL,
                data: "act=get_overhead_id&id=" + letter_id,
                success: function(data) {
                    if (typeof(data.error) != "undefined") {
                        if (data.error != "") {
                            alert(data.error);
                        } else {
		    				var check = FinishOverheadRS(data.overhead_id);
		    				if (check) {
		                        alert("ზედნადები წარმატებით დასრულდა rs.ge-ზე!!!");
		                    }
                        }
                    }

                    $("#continue-rs").button("disable");
					$("#add-rs").button("disable");
					$("#ref-rs").button("disable");
                }
            });
		});
	    $(document).on("click", "#ref-rs", function () {
		    var letter_id	= $("#latter_id").val();
            $.ajax({
                url: aJaxURL,
                data: "act=get_overhead_id&id=" + letter_id,
                success: function(data) {
                    if (typeof(data.error) != "undefined") {
                        if (data.error != "") {
                            alert(data.error);
                        } else {

		    				var check = RefOverheadRS(data.overhead_id);
		    				if (check) {
		                        alert("ზედნადები წარმატებით გაუქმდა rs.ge-ზე!!!");
		                    }
		    				$("#continue-rs").button("disable");
							$("#add-rs").button("disable");
							$("#ref-rs").button("disable");
                        }
                    }
                }
            });
		});

	    $(document).on("click", "#work–blank", function () {
	    	param = new Object();

            //Action
		    param.id	= $("#latter_id").val();
		    param.co	= $("#client_object").val();
		    param.ped	= $("#planed_end_date").val();

	    	var link = $(this).attr("str");
	    	link = "server-side/print/print_letterA.php?id=" + param.id;

	    	var newWin = window.open(link, "JSSite", "width=800,height=800,resizable=yes,scrollbars=yes,status=yes");
	    	newWin.focus();
	    	newWin.onload = function() {
	    		newWin.print();
		    }
	    });

	    $(document).on("click", "#b-print", function () {
	    	param = new Object();

            //Action
		    param.id	= $("#latter_id").val();
		    param.co	= $("#client_object").val();
		    param.ped	= $("#planed_end_date").val();

	    	var link = $(this).attr("str");
	    	link = "server-side/print/print_letterB.php?id=" + param.id;

	    	var newWin = window.open(link, "JSSite", "width=800,height=800,resizable=yes,scrollbars=yes,status=yes");
	    	newWin.focus();
	    	newWin.onload = function() {
	    		newWin.print();
		    }
	    });
/////////////////////---------------------------------ცარიელი ბარათი--------------------------------------/////////////////////////
	    $(document).on("click", "#print_empty", function () {

	        LoadDialog("empty-form");

	    });

	    // Add - Save Service
	    $(document).on("click", "#add-service", function () {
	    	param = new Object();

            //Action
	    	param.act		= "save_service";

		    param.id		= $("#service_id").val();
		    param.lid		= $("#latter_id").val();
		    param.wid		= $("#warehouse_id").val();
		    param.sn		= $("#client_proruction").val();
		    param.sq		= $("#service_quantity").val();
		    param.sc		= $("#service_comment").val();

	    	if(param.sn == ""){
				alert("შეავსეთ სერვისის სახელი!");
			}else if(param.sq == "" || param.q <= 0){
				alert("შეავსეთ რაოდენობა!");
			}else {
			    $.ajax({
			        url: serv_aJaxURL,
				    data: param,
			        success: function(data) {
						if(typeof(data.error) != "undefined")
						{
							if(data.error != "")
							{
								alert(data.error);
							}else
							{
								LoadTable("service_list");
				        		CloseDialog("add-edit-service-form");
								$("#planed_end_date").removeAttr("disabled");
								$("#end_date").removeAttr("disabled");
								$("#request_date").removeAttr("disabled");
								$("#source").removeAttr("disabled");
								$("#responsible_person").removeAttr("disabled");
								$("#car_id").removeAttr("disabled");
								$("#show_planed_end_date").removeAttr("disabled");
								$("#show_same_letters").removeAttr("disabled");
							}
						}
				    }
			    });
			}
		});

	    // Add - Save Guarante
	    $(document).on("click", "#add-guarante", function () {
	    	var client  = GetClientID( $("#client_object").val());
	    	param = new Object();
            //Action
	    	param.act		= "save_guarante";
		    param.id		= $("#guarante_id").val();
		    param.lid		= $("#latter_id").val();
		    param.wid		= $("#warehouse_id").val();
		    param.cp		= $("#client_guarante_proruction").val();
		    param.sn		= $("#serial_number").val();
		    param.sc		= $("#guarante_comment").val();

	    	if(param.sn.length != 15){
				alert("შტრიხკოდი არაწორია!");
	    	}else if(client!=parseInt(param.sn.substring(1,5))){
					alert("კლიენტი  არაწორია!");
    		}else if(param.sq == "" || param.q <= 0){
					alert("შეავსეთ რაოდენობა!");
			}else {
			    $.ajax({
			        url: guar_aJaxURL,
				    data: param,
			        success: function(data) {
						if(typeof(data.error) != "undefined")
						{
							if(data.error != "")
							{
								alert(data.error);
							}else
							{
								LoadTable("guarante_list");
								LoadTable("service_list");
				        		CloseDialog("add-edit-guarante-form");
								$("#planed_end_date").removeAttr("disabled");
								$("#end_date").removeAttr("disabled");
								$("#request_date").removeAttr("disabled");
								$("#source").removeAttr("disabled");
								$("#responsible_person").removeAttr("disabled");
								$("#car_id").removeAttr("disabled");
								$("#show_planed_end_date").removeAttr("disabled");
								$("#show_same_letters").removeAttr("disabled");
							}
						}
				    }
			    });
			}
		});

        $(document).on("click", ".combobox", function (event) {
	    	var i = $(this).text();
			$("#" + i).autocomplete( "search", "" );
		});

        $(document).on("click", ".new_requester", function (event) {
	    	if($(this).is(":checked")){
	    		$("#new_requester").css("display", "block");
	    		$("#requester").css("display", "none");
		    }else{
		    	$("#new_requester").val('');
	    		$("#new_requester").css("display", "none");
	    		$("#requester").css("display", "block");
			}
		});

        $(document).on("click", "#show_planed_end_date", function () {
			param = new Object();
			param.act  		= "show_planed_end_date";
			param.warehouse_id	= $("#warehouse_id").val();
			param.local_id	= $("#latter_id").val();
		    $.ajax({
		        url: aJaxURL,
			    data: param,
		        success: function(data) {
					if(typeof(data.error) != "undefined"){
						if(data.error != ""){
							alert(data.error);
						}else{
							$("#show-form").html(data.page);
							LoadDialog("show-planed-end-date");
						}
					}
			    }
		    });
		});

        $(document).on("click", "#show_same_letters", function () {

			param = new Object();
			param.act  = "show_same_letters";

		    $.ajax({
		        url: aJaxURL,
			    data: param,
		        success: function(data) {
					if(typeof(data.error) != "undefined"){
						if(data.error != ""){
							alert(data.error);
						}else{
							$("#show-form").html(data.page);
							LoadDialog("show-same-letters");
						}
					}
			    }
		    });
		});


		$(document).on("keydown", "#serial_number", function (event) {
			if (event.keyCode == $.ui.keyCode.ENTER){
				param = new Object();
				param.act = "get_cartridge";
				param.barcode = $("#serial_number").val();
				param.client  = GetClientID( $("#client_object").val() );

			    $.ajax({
			        url: guar_aJaxURL,
				    data: param,
			        success: function(data) {
						if(typeof(data.error) != "undefined"){
							if(data.error != ""){
								alert(data.error);
							}else{
								$("#client_guarante_proruction").val(data.cartridge);
							}
						}
				    }
			    });
				event.preventDefault();					//Clear Dialog Default <b>keypress<b> Event
            }
		});

		$(document).on("keydown", "#client_object", function (event) {
			if (event.keyCode == $.ui.keyCode.ENTER){
				var client_name = $("#client_object").val();

				GetClientPersons(client_name);
				$(".inner-table").find(":input").prop("disabled", false);
				$("#client_object").attr("disabled", "disabled");
				event.preventDefault();					//Clear Dialog Default <b>keypress<b> Event
            }
		});

		$(document).on("click", "#client_object-widget", function () {
			var client_name = $("#client_object").val();

			GetClientPersons(client_name);
			$(".inner-table").find(":input").prop("disabled", false);
			$("#client_object").attr("disabled", "disabled");
			event.preventDefault();					//Clear Dialog Default <b>keypress<b> Event
		});

	    $(document).on("change", "#request_date", function () {
	    	var letter_id 	= $("#latter_id").val();
	    	var warehouse_id  = $("#warehouse_id").val();
		    var client_name = $("#client_object").val();
	    	var client_id 	= GetClientID(client_name)
		    $.ajax({
		        url:"server-side/letters/letterA.action.php",
			    data: "act=get_end_date&r_d="+this.value + "&client=" + client_id + "&letter_id=" + letter_id + "&warehouse_id="+ warehouse_id + "&clien_obj="+clien_obj,
	    	    success: function(data) {
					if(typeof(data.error) != "undefined"){
						if(data.error != ""){
							alert(data.error);
						}else{
							$("#end_date").val(data.end_date);
							$("#planed_end_date").val(data.pln_date);
						}
					}
			    }
		    });

	    });

		function CheckPlannedEndDate(letter_id){
	    	param = new Object();

            //Action
	    	param.act	= "check_p_end_date";
		    param.id	= letter_id;
		    param.ped	= $("#planed_end_date").val();

		    $.ajax({
		        url: aJaxURL,
			    data: param,
		        success: function(data) {
					if(typeof(data.error) != "undefined"){
						if(data.error != ""){
							alert(data.error);
						}else{
							if(data.answ == "1"){
								alert("ამ გეგმიურ დროზე სხვა ბარათი უკვე არსებობს!");
							}else{
								//CloseDialog(fName);
							}

						}
					}
			    }
		    });
		}

		function SaveLatter(letter_id, send_rs){
			$("#client_ob_trans_div").remove();
			var check	= CheckList(letter_id);
        	if(check){
		    	param = new Object();

	            //Action
		    	param.act	= "save_latter";
			    param.id	= letter_id;
			    param.wid	= $("#warehouse_id").val();
			    param.s		= $("#source").val();
			    param.rd	= $("#request_date").val();
			    param.ovch    = $("#overhead_check").is(":checked");
			    param.ped	= $("#planed_end_date").val();
			    param.pri	= $("#priority").val();
			    param.ed	= $("#end_date").val();
			    param.fed	= $("#fact_end_date").val();
			    param.rp	= $("#responsible_person").val();
			    param.co	= $("#client_object").val();
			    param.req	= $("#requester").val();
			    param.nreq	= $("#new_requester").val();
			    param.rec	= $("#receiver").val();
			    param.ci	= $("#car_id").val();
			    param.price = trans_price;		    

			    param.c		= $("#comment").val();

			    if(param.rd == ""){
				    alert("შეავსეთ შეკვეთის თარიღი!");
				}else{
				    $.ajax({
				        url: aJaxURL,
					    data: param,
				        success: function(data) {
							if(typeof(data.error) != "undefined")
							{
								if(data.error != "")
								{
									alert(data.error);
								}else
								{
									if(send_rs){
								    	var check = SendRS(letter_id);
								    	if(check){
							                alert("ზედნადები წარმატებით გაიგზავნა rs.ge-ზე!!!");
							                CloseDialog(fName);
								    	}

									}
								//	CloseDialog(fName);
									$("#add-rs").button("enable");
									$("#save-dialog").button("disable");
									LoadTable(fName);
								}
							}
					    }
				    });
				}
        	}
		}

        function SendRS(letter_id) {
            var check = false;
            $.ajax({
                url: wsdlURL,
                async: false, //r-value
                data: "act=send_aletter&id=" + letter_id + "&trans_type=" + trans_type + "&price=" + trans_price,
                success: function(data) {
                    if (typeof(data.error) != "undefined") {
                        if (data.error != "") {
                            alert(data.error);
                        } else {
                            check = true;
                        }
                    }
                }
            });
            trans_type=0;
            trans_price=0;
            return check;
        }

        function FinishOverheadRS(rs_id) {
            var check = false;
            $.ajax({
                url: wsdlURL,
                async: false, //r-value
                data: "act=finish_overhead&rs_id=" + rs_id,
                success: function(data) {
                    if (typeof(data.error) != "undefined") {
                        if (data.error != "") {
                            alert(data.error);
                        } else {
                            check = true;
                        }
                    }
                }
            });
            return check;
        }
        function RefOverheadRS(o_id) {
            var check = false;
            $.ajax({
                url: wsdlURL,
                async: false, //r-value
                data: "act=RefOverheadRS&rs_id=" + o_id,
                success: function(data) {
                    if (typeof(data.error) != "undefined") {
                        if (data.error != "") {
                            alert(data.error);
                        } else {
                            check = true;
                        }
                    }
                }
            });
            return check;
        }


        function CheckList(list_id) {
        	var warehouse_id	= $("#warehouse_id").val();
            var check = false;
            $.ajax({
                url: aJaxURL,
                async: false, //r-value
                data: "act=check_list&id=" + warehouse_id,
                success: function(data) {
                    if (typeof(data.error) != "undefined") {
                        if (data.error != "") {
                            alert(data.error);
                        } else {
                            check = true;
                        }
                    }
            	}
        	});
            return check;
        }

		/**
		* Get next auto incremented id
		* @return {int}   Returns a next id
		*/
		function GetLocalID(){
			var local_id;
			$.ajax({
		        url: aJaxURL,
        		async: false, //r-value
			    data: "act=get_local_id",
		        success: function(data) {
					if(typeof(data.error) != "undefined"){
						if(data.error != ""){
							alert(data.error);
						}else{
							local_id = data.local_id;
						}
					}
			    }
		    });
	      	return local_id;
		}

		function GetClientID(client_name){
			var client_id;
			$.ajax({
		        url: aJaxURL,
        		async: false, //r-value
			    data: "act=get_client_id&cn=" + client_name,
		        success: function(data) {
					if(typeof(data.error) != "undefined"){
						if(data.error != ""){
							alert(data.error);
						}else{
							client_id = data.client_id;
						}
					}
			    }
		    });
	      	return client_id;
		}

		function GetClientObjectID(client_name){
			var client_id;
			$.ajax({
		        url: aJaxURL,
        		async: false, //r-value
			    data: "act=get_client_object_id&cn=" + client_name,
		        success: function(data) {
					if(typeof(data.error) != "undefined"){
						if(data.error != ""){
							alert(data.error);
						}else{
							client_id = data.client_obj_id;
						}
					}
			    }
		    });
	      	return client_id;
		}

		function GetClientPersons(client_name){
			$.ajax({
		        url: aJaxURL,
			    data: "act=get_client_persons&cn=" + client_name,
		        success: function(data) {
					if(typeof(data.error) != "undefined"){
						if(data.error != ""){
							alert(data.error);
						}else{
							$("#requester").html(data.client_persons);
							$("#client_ob_trans").val(data.trans);
							clien_obj=data.id;
						}
					}
			    }
		    });
		}

        function ClearDB() {
            $.ajax({
                url: aJaxURL,
                data: "act=clear_db",
                success: function(data) {
                    if (typeof(data.error) != "undefined") {
                        if (data.error != "") {
                            alert(data.error);
                        }
                    }
                }
            });
        }
    </script>
    <style type="text/css">
    
 .radio {
  background:#C9C9C9 !important;
  border:none !important;	
  color: #fff !important;  	
}

.ui-button.ui-state-active .ui-button-text {
  background-image: linear-gradient(to bottom, #8aaaff, #006db0);
  color: #fff; 
  border-radius:5px; 	
}    
    
</style>
</head>

<body>
    <div id="tabs" style="width: 1140px; margin: 0 auto; min-height: 0px;">
		<ul>
			<li><a href="#tab-0">მიღებული</a></li>		
			<li><a href="#tab-1">წარმოებაშია</a></li>	
			<li><a href="#tab-3">წარმოება დასრულებული</a></li>		
			<li><a href="#tab-4">შეფუთული</a></li>
			<li><a href="#tab-4">გზაშია</a></li>
			<li><a href="#tab-5">არქივი</a></li>				
		</ul>
	<div id="tab-0"></div>
	<div id="tab-1"></div>
	<div id="tab-2"></div>
	<div id="tab-3"></div>
	<div id="tab-4"></div>
	<div id="tab-5"></div>
	<div id="tab-6"></div>			
    <div id="dt_example" class="ex_highlight_row">

        <div id="container">
            <div id="dynamic">
            	<h2 align="center">ა ბარათები</h2>
            	<div id="button_area">            	
        			<button id="add_button">ახალი ა ბარათი</button>
        			<button id="print_empty">ცარიელი ა ბარათის ბეჭდვა</button>
        			<button id="delete_button">წაშლა</button>
        			
        		</div>
                <table class="display" id="example">
                    <thead>
                        <tr id="datatable_header">
                            <th>ID</th>
                            <th class="min" title="ა-ბარათის  შეკვეთის თარიღი">შეკვეთის თარიღი</th>
                            <th style="width:100px;">ნომერი</th>
                            <th style="width: 100%">ობიექტი</th>
                            <th class="min" title="დასრულების გეგმიური დრო">გეგმ. დრო</th>
                            <th class="min" title="შეფუთვის თარიღი">შეფუთვის  დრო</th>
                            <th style="width: 180px;">სტატუსი</th>
                            <th class="check">#</th>
                        </tr>
                    </thead>
                    <thead>
                        <tr class="search_header">
                            <th class="colum_hidden">
                            	<input type="text" name="search_id" value="ფილტრი" class="search_init" />
                            </th>
                            <th>
                                <input type="text" name="order_date" value="ფილტრი" class="search_init" />
                            </th>
                            <th>
                            	<input style="width:70px;" type="text" name="search_number" value="ფილტრი" class="search_init" />
                            </th>
                            <th>
                                <input type="text" name="order_object" value="ფილტრი" class="search_init" />
                            </th>
                            <th>
                                <input type="text" name="orderer" value="ფილტრი" class="search_init" />
                            </th>
                            <th>
                                <input type="text" name="status" value="ფილტრი" class="search_init" />
                            </th>
                            <th>
                                <input type="text" name="status" value="ფილტრი" class="search_init" />
                            </th>
                              <th>
                            	<input type="checkbox" name="check-all" id="check-all">
                            </th>
                        </tr>
                    </thead>
                </table>
            </div>
            <div class="spacer">
            </div>
        </div>
    </div>
    </div>	
     <div>
    	<input type="hidden" id="chechedStatus" value="true"/>
    </div>
    <!-- jQuery Dialog -->
    <div id="add-edit-form" class="form-dialog" title="ა ბარათი">
    	<!-- aJax -->
	</div>
		<!-- jQuery Dialog -->
    <div id="add-edit-service-form" class="form-dialog" title="სერვისი">
    	<!-- aJax -->
	</div>
	<!-- jQuery Dialog -->
    <div id="add-edit-guarante-form" class="form-dialog" title="საგარანტიო">
    	<!-- aJax -->
	</div>
    <div id="show-form" class="form-dialog" title="ბარათები">
    	<!-- aJax -->
	</div>
	<div id="empty-form" class="form-dialog" title="ბარათები">
    	<!-- aJax -->
	</div>
	
</body>
</html>